import type { Recordable } from '@vben/types';

import type { Page } from '../base';

import { requestClient } from '#/api/request';

export namespace LimbDeviceFirmwareApi {
  export interface LimbDeviceFirmware {
    [key: string]: any;
    id: string;
    name: string;
    version: string;
    fileData?: string;
    description?: string;
    status?: number;
    releaseState?: number;
    isDeleted?: boolean;
    createdAt?: string;
    updatedAt?: string;
    deletedAt?: string;
    models?: any[];
  }

  export interface DeviceFirmwareUpdateInput {
    status?: number;
    isDeleted?: boolean;
    createdAt?: string;
    updatedAt?: string;
    deletedAt?: string;
    fileData?: string;
    description?: string;
    name?: string;
    version?: string;
    models?: string[];
    releaseState?: number;
  }
}

/**
 * 获取设备固件列表
 */
async function getDeviceFirmwareList(params: Recordable<any>) {
  return requestClient.get<Page<LimbDeviceFirmwareApi.LimbDeviceFirmware>>(
    '/limb/device-firmware/list',
    { params },
  );
}

/**
 * 创建设备固件
 * @param data 设备固件数据
 */
async function createDeviceFirmware(
  data: LimbDeviceFirmwareApi.DeviceFirmwareUpdateInput,
) {
  return requestClient.post('/limb/device-firmware', data);
}

/**
 * 更新设备固件
 *
 * @param id 设备固件 ID
 * @param data 设备固件数据
 */
async function updateDeviceFirmware(
  id: string,
  data: LimbDeviceFirmwareApi.DeviceFirmwareUpdateInput,
) {
  return requestClient.put(`/limb/device-firmware/${id}`, data);
}

/**
 * 删除设备固件
 * @param id 设备固件 ID
 */
async function deleteDeviceFirmware(id: string) {
  return requestClient.delete(`/limb/device-firmware/${id}`);
}

export {
  createDeviceFirmware,
  deleteDeviceFirmware,
  getDeviceFirmwareList,
  updateDeviceFirmware,
};
